﻿using System;
using System.Collections.Generic;
using System.Web;
using PayRoller.Code;
using System.Web.SessionState;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using HySoft.Cash.Business;
using HySoft.Cash.Structure;
using System.Configuration;
using System.Web.Profile;
using System.Web.UI;
using System.Data;

namespace PayRoller.Manage.OrgInfo
{
    public class ReceivingNew : Page, IRequiresSessionState
    {
        // Fields
        protected Button bnSave;
        protected DropDownList DropDownList1;
        public int OrgSid;
        protected TextBox txtPaymentAmount;
        protected TextBox txtPaymentDate;

        // Methods
        protected void bnSave_Click(object sender, EventArgs e)
        {
            if (base.Request["OrgSid"] != null)
            {
                int num = Convert.ToInt32(base.Request["OrgSid"]);
                TrecpaymentBN tbn = new TrecpaymentBN(this.Page);
                TrecpaymentDT detail = new TrecpaymentDT();
                detail.OrgSid = num;
                detail.InvoiceSid = Convert.ToInt32(this.DropDownList1.SelectedValue);
                detail.PaymentDate = this.txtPaymentDate.Text;
                detail.PaymentAmount = Convert.ToDecimal(this.txtPaymentAmount.Text);
                tbn.Add(detail);
                tbn.Dispose();
                tbn = null;
                base.ClientScript.RegisterStartupScript(base.GetType(), "", "<script>alert('Success!');window.location='ReceivingList.aspx?OrgSid=" + num.ToString() + "';</script>");
            }
        }

        public void GetInvoiceList(int OrgSid)
        {
            ListItem item = new ListItem();
            TinvoicelistBN tbn = new TinvoicelistBN(this.Page);
            tbn.QueryOrgSid(OrgSid);
            tbn.QueryIsValidNot(InvoiceStatuses.Deleted);
            //tbn.QueryIsValid(1);
            DataTable list = tbn.GetList();
            for (int i = 0; i < list.Rows.Count; i++)
            {
                item = new ListItem(list.Rows[i]["InvoiceDate"].ToString() + " - " + list.Rows[i]["InvoiceAmount"].ToString(), list.Rows[i]["Sid"].ToString());
                this.DropDownList1.Items.Add(item);
            }
            tbn.Dispose();
            tbn = null;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.bnSave.Attributes.Add("onclick", "return Check();");
            if (base.Request["OrgSid"] != null)
            {
                this.OrgSid = Convert.ToInt32(base.Request["OrgSid"]);
                this.GetInvoiceList(this.OrgSid);
            }
        }

        // Properties
        protected HttpApplication ApplicationInstance
        {
            get
            {
                return this.Context.ApplicationInstance;
            }
        }

        protected DefaultProfile Profile
        {
            get
            {
                return (DefaultProfile)this.Context.Profile;
            }
        }
    }

}
